<template>
  <div>
      <select v-model="auth" name="" id="">
          <option value="管理员">管理员</option>
          <option value="老师">老师</option>
          <option value="学生">学生</option>
      </select>
      <div>
          <button @click="login">登录</button>
      </div>
  </div>
</template>

<script>
import admin from '../router/auth/admin'
import teac from '../router/auth/teac'
import stu from '../router/auth/stu'

import { filterRoutes } from '../utils'
export default {
    data() {
        return {
            auth: ""
        }
    },
    methods: {
        login() {
            // 动态路由  动态添加(刷新会丢失)
            // switch(this.auth) {
            //     case "管理员":
            //         this.$router.addRoutes(admin)
            //         break;
            //     case "老师":
            //         this.$router.addRoutes(teac)
            //         break;
            //     case "学生":
            //         this.$router.addRoutes(stu)
            //         break;
            // }
            // this.$router.push('/list')


            // 第二种方式
            // admin
            let arr = []
            // 对数据进行筛选
            arr = filterRoutes(admin, this.auth)
            this.$router.addRoutes(arr)
            this.$router.push('/list')
        }
    }
}
</script>

<style>

</style>